package com.test.boot.http.rpc.client.config;

import com.test.boot.http.rpc.api.service.DemoService;
import com.test.boot.http.rpc.api.service.HelloService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
import org.springframework.remoting.support.SimpleHttpServerFactoryBean;

/**
 * Created by hujianjun on 2015/12/4.
 */
@Configuration
public class RpcClientConfig {

    @Bean
    public HttpInvokerProxyFactoryBean helloProxy() {
        HttpInvokerProxyFactoryBean proxyFactoryBean = new HttpInvokerProxyFactoryBean();
        proxyFactoryBean.setServiceInterface(HelloService.class);
        proxyFactoryBean.setServiceUrl("http://localhost:8080/hello");
        return proxyFactoryBean;
    }

    @Bean
    public HelloService helloService() {
        HttpInvokerProxyFactoryBean proxyFactoryBean = helloProxy();
        return (HelloService)proxyFactoryBean.getObject();
    }

    @Bean
    public HttpInvokerProxyFactoryBean demoProxy() {
        HttpInvokerProxyFactoryBean proxyFactoryBean = new HttpInvokerProxyFactoryBean();
        proxyFactoryBean.setServiceInterface(DemoService.class);
        proxyFactoryBean.setServiceUrl("http://localhost:8080/demo");
        return proxyFactoryBean;
    }

    @Bean
    public DemoService demoService() {
        HttpInvokerProxyFactoryBean proxyFactoryBean = demoProxy();
        return (DemoService)proxyFactoryBean.getObject();
    }
}
